<!--
* @author wn
* @date 2023/07/31 11:41:47
* @description: 自定义轮播图 通用组件
!-->
<template>
	<view class="carousel">
		<!-- circular:是否采用衔接滑动，即播放到末尾后重新回到开头 -->
		<swiper :circular="true" autoplay :interval="3000" @change="onChange">
			<swiper-item v-for="item in list" :key="item.id">
				<navigator
					url="/pages/index/index"
					hover-class="none"
					class="navigator"
				>
					<image mode="aspectFill" :src="item.imgUrl"></image>
				</navigator>
			</swiper-item>
		</swiper>
		<!-- 指示点 -->
		<view class="indicator">
			<text
				v-for="(item, index) in list"
				:key="item.id"
				class="dot"
				:class="{ active: index === activeIndex }"
			></text>
		</view>
	</view>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
// bannerList
defineProps<{ list: BannerItem[] }>()

// 实时 下标
const activeIndex = ref(0)

// 轮播图改变时触发
const onChange: UniHelper.SwiperOnChange = event => {
	activeIndex.value = event.detail.current
}
</script>
<style lang="scss">
/* 轮播图 */
.carousel {
	height: 280rpx;
	position: relative;
	overflow: hidden;
	// transform: translateY(0);
	background-color: #efefef;
	.indicator {
		display: flex;
		justify-content: center;
		position: absolute;
		left: 0;
		right: 0;
		bottom: 16rpx;
		.dot {
			width: 30rpx;
			height: 6rpx;
			margin: 0 8rpx;
			border-radius: 6rpx;
			background-color: rgba(255, 255, 255, 0.4);
		}
		.active {
			background-color: #fff;
		}
	}
	.navigator {
		width: 100%;
		height: 100%;
	}
}
</style>
